How to open a chat window in sender and receiver side [on hold]

Posted by DEEPS on Stack Overflow See other posts from Stack Overflow or by DEEPS
Published on 2013-06-27T13:37:58Z Indexed on 2013/06/28 4:21 UTC
Read the original article Hit count: 95

Filed under:
|

When i am trying to send a message from sender the chat window is always opening in senders side instead of receiver side.so please give a correct code to display chat box in both side. (HTML 5, JAVASCRIPT,JQUERY).

   This is client side code:
 //Send private message
function sendPvtMsg(data)
 {
 var pvtmsg = data;
 socket.emit('message',JSON.stringify({msg: 'pvtMsg',
    data: {
        from: userName,
        to: toChat,
        pvtmsg: data
    }}),roomId);
}


socket.on('message',function(data)
    {
    var command = JSON.parse(data);
     var itemName = command.msg;
     var rec_data = command.data.message;
     var sender = command.data.name;
     //Receive message from server
     if (itemName == "message")
     {
         document.getElementById("chat").value += sender + " : " + rec_data + "\n";
     }
     //Receive private message
     else if (itemName == "pvtMsg")
     {
         var to = command.data.to;
         var from = command.data.from;
         //To display message to sender and receiver
         if (userName == to || userName == from)
         {
             var pvtmsg = command.data.pvtmsg;
             document.getElementById("chat").value += from + "( to " + to + ")" + " : " + pvtmsg + "\n";
         }
     }
function createChatBox(chatboxtitle,minimizeChatBox) {
if ($("#chatbox_"+chatboxtitle).length > 0) {
    if ($("#chatbox_"+chatboxtitle).css('display') == 'none') {
        $("#chatbox_"+chatboxtitle).css('display','block');
        restructureChatBoxes();
    }
    $("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus();
    return;
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html5